//package main;
//
//import bots.FirstNNBot;
//import bots.lookahead.LightLookAheadBot;
//import bots.lookahead.SimpleLookAheadBot;
//import model.GameRecord;
//import model.GameType;
//import model.PositionType;
//import model.Player;
//import org.apache.log4j.Logger;
//import util.Bag;
//import util.Util;
//
//import java.io.FileNotFoundException;
//import java.util.HashSet;
//import java.util.List;
//import java.util.Set;
//import java.util.concurrent.ForkJoinPool;
//
///**
// * @author Alex Vikharev alex.vikharev@gmail.com
// *         created 04.02.12
// */
//public class TeachablePlayerGame {
//    private static final Logger log = Logger.getLogger(TeachablePlayerGame.class);
//
//    public static void main(String[] args) throws FileNotFoundException {
//        ForkJoinPool pool = new ForkJoinPool();
//        Player bot2 = new LightLookAheadBot(GameType.SIMPLE, "Look ahead bot", 3, pool);
//        Player bot1 = new LightLookAheadBot(GameType.SIMPLE, "Light look ahead bot", 3, pool);
//
////        Player bot3 = new SimpleLookAheadBot(GameType.SIMPLE, "Look ahead", 2, pool);
////        Player bot4 = new RandomBot("Bot 4");
//
//        testPlay(bot1, bot2);
////        learnPlay(bot3, bot4, bot2, 10000);
////        for (int i = 0; i < 2; i++) {
////            testPlay(bot1, bot2);
////            learnPlay(bot4, bot2, bot2, 10000);
////        }
////        for (int i = 0; i < 2; i++) {
////            testPlay(bot1, bot2);
////            learnPlay(bot1, bot2, bot2, 10000);
////        }
////        for (int i = 0; i < 2; i++) {
////            testPlay(bot1, bot2);
////            learnPlay(bot3, bot2, bot2, 10000);
////        }
////
////        testPlay(bot1, bot2);
////        Util.saveClassifier(bot2.getNetwork(), "first-bot.classifier");
//    }
//
//    private static void testPlay(Player bot1, Player bot2) {
//        int firstWin = 0;
//        int secondWin = 0;
//        int tie = 0;
////        bot2.resetStatistics();
//        log.info("Start testing games");
//        int runs = 100;
//        for (int t = 0; t < runs; t++) {
//            if (t % 10 == 0) {
//                log.info("Test game " + t);
//            }
//
//            Game game = new Game(bot1, bot2, GameType.SIMPLE);
//
//            game.go();
//            switch (game.getState()) {
//                case FIRST_PLAYER_WIN:
//                    firstWin++;
//                    break;
//                case SECOND_PLAYER_WIN:
//                    secondWin++;
//                    break;
//                default:
//                    tie++;
//            }
//            log.debug(game.getState());
//        }
//        log.info(String.format("First player (%s) wins: %d Second player (%s) wins: %d Ties: %d", bot1.toString(), firstWin, bot2.toString(), secondWin, tie));
////        log.info(String.format("NNBot random moves percent: %.2f", bot2.getRandomMovesPercent()));
//    }
//
//    private static void learnPlay(Player bot1, Player bot2, Player bot3, int runs) {
//        Bag<PositionType> goodMoves = new Bag<>();
//        Bag<PositionType> badMoves = new Bag<>();
//        for (int t = 0; t < runs; t++) {
//            Game game = new Game(bot1, bot2, GameType.SIMPLE);
//
//            game.go();
//            final GameRecord gameRecord = game.getGameRecord();
//            List<PositionType> list1 = gameRecord.getFirstPlayerMoves();
//            List<PositionType> list2 = gameRecord.getSecondPlayerMoves();
//            List<PositionType> firstPlayerMoves = Util.TO_CANONICAL.apply(list1);
//            List<PositionType> secondPlayerMoves = Util.TO_CANONICAL.apply(list2);
//            switch (game.getState()) {
//                case FIRST_PLAYER_WIN:
//                    goodMoves.addAll(firstPlayerMoves);
//                    badMoves.addAll(secondPlayerMoves);
//                    break;
//                case SECOND_PLAYER_WIN:
//                    badMoves.addAll(firstPlayerMoves);
//                    goodMoves.addAll(secondPlayerMoves);
//                    break;
//                default:
//            }
//
//            if (t % (runs / 100) == 0) {
//                log.info(String.format("Played games: %.0f%%", t * 100.0 / runs));
//            }
//        }
//        log.info("Good moves: " + goodMoves.size() + " Bad moves: " + badMoves.size());
//
//        Set<PositionType> allMoves = new HashSet<>(goodMoves.size() + badMoves.size());
//        for (PositionType goodMove : goodMoves) {
//            allMoves.add(goodMove);
//        }
//        for (PositionType badMove : badMoves) {
//            allMoves.add(badMove);
//        }
//
//
//        for (PositionType move : allMoves) {
//            if (badMoves.contains(move) && goodMoves.contains(move)) {
//                int badTimes = badMoves.get(move);
//                int goodTimes = goodMoves.get(move);
//                if (badTimes > goodTimes) {
//                    goodMoves.remove(move);
//                } else {
//                    badMoves.remove(move);
//                }
//            }
//        }
//
//
//        log.info("After filtering. Good moves: " + goodMoves.size() + " Bad moves: " + badMoves.size());
//        bot3.teach(goodMoves, badMoves);
//    }
//
//
//}
